Skip to content

TS solana binding generator#502

Merged
ernest-nowacki merged 15 commits into
mainfrom
feat/solana-ts-bindings
Jul 6, 2026
Merged

TS solana binding generator#502
ernest-nowacki merged 15 commits into
mainfrom
feat/solana-ts-bindings

Conversation

@ernest-nowacki

@ernest-nowacki ernest-nowacki commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

TypeScript binding generator

cmd/generate-bindings/solana/tsbindgen.go (in the CLI repo) generates two files from an Anchor IDL:

  • A binding class (<ProgramName>.ts) that:
    • Embeds the full IDL as a typed const.
    • Derives @solana/codecs codec expressions for every IDL type (structs, scalar enums, options, vecs, fixed arrays, all primitive types including pubkeys).
    • Sorts types so each codec const only references already-declared codecs.
    • Generates writeReport, writeReportFromBorshEncodedVec, writeReportFrom<Struct>, and writeReportFrom<Struct>s methods for every struct type.
    • Generates account and event decoders with discriminator validation (decode<Name>Account, decode<Name>Event).
  • A mock file (<ProgramName>_mock.ts) that wires the binding class against addSolanaContractMock for use in unit tests.

For the end user

The binding command will use the path contracts/solana/src/idl/ by default when --idl is not specified. So user workflow directory structure would look like this:

<project-root>/
  contracts/
    solana/
      src/
        idl/          ← drop your Anchor IDL .json files here
        generated/    ← Go bindings written here
      ts/
        generated/    ← TypeScript bindings written here

Command scans every *.json in the idl directory and generates one binding class per file. You can also pass a single file with --idl path/to/contract.json. Language is auto-detected from whether the project contains .go or .ts files, or override with --language typescript.

@ernest-nowacki ernest-nowacki marked this pull request as ready for review June 30, 2026 08:47
@ernest-nowacki ernest-nowacki requested a review from a team as a code owner June 30, 2026 08:47

@timothyF95 timothyF95 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@ernest-nowacki ernest-nowacki added this pull request to the merge queue Jul 6, 2026
Merged via the queue into main with commit d55410a Jul 6, 2026
22 checks passed
@ernest-nowacki ernest-nowacki deleted the feat/solana-ts-bindings branch July 6, 2026 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants